package DataStore
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.Dictionary;
	import GameLogic.ENUM;
	import GameLogic.Game;
	import LoadUnit.LoadManager;
	import Map.MapManager;
	public class BmpDataPool
	{
		public static var MapPool:Dictionary = new Dictionary();
		public static var RobotPool:Dictionary = new Dictionary();
		public static var WeaPool:Dictionary = new Dictionary();
		public static var LuaeditPool:Dictionary = new Dictionary();
		public static var LargeSource:Dictionary = new Dictionary();
		
		
		//public static var LuaeditPool:Dictionary = new Dictionary();
		public static var LuaEditPoolIndexInit:int = 100;
		public static var LuaEditPoolIndex:int = LuaEditPoolIndexInit;
		public static var MaxImgs:int = 0;
        public static var WeaponPool:Dictionary = new Dictionary();		
		public static var WeaponIndex:int  = 100;	
		
		public static var ParseImgsFinished:Boolean = false;
		
		public function BmpDataPool()
		{
		}
		
		public static function AddImgToPool(_bmp:BitmapData,_name:String,_pool:Dictionary):void
		{
			_pool[_name] = _bmp;
		}
		
		/**
		 * 脚本方法，以设置需要载入的图片数量，作为结束标志
		 */
		public static function SetImgMax(_n:int):void
		{
			MaxImgs = _n;
		}
		
		public static function AddImgToEditPool(_bmp:BitmapData):void
		{
			LuaEditPoolIndex++;
			LuaeditPool[LuaEditPoolIndex] = _bmp;
			if (LuaEditPoolIndex >= (MaxImgs + LuaEditPoolIndexInit))
			{
				Game.ImgResourceReady();
			}
		}
		
		public static function AddImgToWeaponPool(_bmp:BitmapData):void
		{
			WeaponIndex++;
			WeaponPool[WeaponIndex]  = _bmp;
		}
		
		public static function ParseMap(_id:int, _x:int, _y:int, _w:int, _h:int):void
		{
			var tile:BitmapData = new BitmapData(_w, _h);
			tile.copyPixels(LargeSource[11], new Rectangle(_x, _y, _w, _h), new Point(0, 0));
			MapPool[_id] = tile;
		}
		
		public static function ParseRobot(_id:int, _x:int, _y:int, _w:int, _h:int):void
		{
			var tile:BitmapData = new BitmapData(_w, _h);
			tile.copyPixels(LargeSource[12], new Rectangle(_x, _y, _w, _h), new Point(0, 0));
			RobotPool[_id] = tile;
		}
		
		public static function ParseWeapon(_id:int, _x:int, _y:int, _w:int, _h:int):void
		{
			var tile:BitmapData = new BitmapData(_w, _h);
			tile.copyPixels(LargeSource[14], new Rectangle(_x, _y, _w, _h), new Point(0, 0));
			WeaPool[_id] = tile;
		}
		
		public static function ParseLuaeditimg(_id:int, _x:int, _y:int, _w:int, _h:int):void
		{
			var tile:BitmapData = new BitmapData(_w, _h);
			tile.copyPixels(LargeSource[13], new Rectangle(_x, _y, _w, _h), new Point(0, 0));
			LuaeditPool[_id] = tile;
		}
		
		private static function ShowInfo(_id:int):void
		{
		}
		
		/**
		 * 通知资源解析工作完成ParseLuaeditimg
		 */
		public static function NotifyParseFinished():void
		{
			ParseImgsFinished = true;
			LoadManager.loadline.visible = false;
			/**
			LoadManager.loadline.scaleX = 3;
			var la:Dictionary = RobotPool;
			var lb:Dictionary = MapPool;
			var lc:Dictionary = WeaPool;
			var ld:Dictionary = LuaeditPool;
			var i:int = 1;
			for each (var item:BitmapData in la)
			{
				LoadManager.loadline.visible = false;
				var tile:Bitmap = new Bitmap(item);
				var x:int = (i % 20) * 50;
				var y:int = (i / 20) * 50;
				tile.x = x;
				tile.y = y;
				Game.MainCanvas.addChild(tile);
				i++;
			}
			for each (var item:BitmapData in lb)
			{
				LoadManager.loadline.visible = false;
				var tile:Bitmap = new Bitmap(item);
				var x:int = (i % 20) * 50;
				var y:int = (i / 20) * 50;
				tile.x = x;
				tile.y = y;
				Game.MainCanvas.addChild(tile);
				i++;
			}
			for each (var item:BitmapData in lc)
			{
				LoadManager.loadline.visible = false;
				var tile:Bitmap = new Bitmap(item);
				var x:int = (i % 20) * 50;
				var y:int = (i / 20) * 50;
				tile.x = x;
				tile.y = y;
				Game.MainCanvas.addChild(tile);
				i++;
			}
			for each (var item:BitmapData in ld)
			{
				LoadManager.loadline.visible = false;
				var tile:Bitmap = new Bitmap(item);
				var x:int = (i % 20) * 50;
				var y:int = (i / 20) * 50;
				tile.x = x;
				tile.y = y;
				Game.MainCanvas.addChild(tile);
				i++;
			}**/
			
			
		}
		
	}
}